﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Contoso.Models;

namespace Contoso.DAL
{
    public class StudentsRepository : IStudentsRepository
    {
        private SchoolContext context;

        public StudentsRepository(SchoolContext context)
        {
            this.context = context;
        }

        public IQueryable<Student> Students()
        {
            return context.Students.ToList().AsQueryable();
        }

        public Student Find(int Id)
        {
            return context.Students.Where(x => x.StudentID == Id).SingleOrDefault();
        }

        public void Add(Student student)
        {
            context.Students.Add(student);
            context.SaveChanges();
        }

        public void Delete(Student Student)
        {
            var originalStudent = context.Students.Find(Student.StudentID);
            context.Students.Remove(originalStudent);
            context.SaveChanges();
        }

        public void Save()
        {
            context.SaveChanges();
        }




    }
}